using Senparc.Weixin.Entities;
using Senparc.Weixin.MP.AdvancedAPIs.Card;
using Senparc.Weixin.MP.CommonAPIs;
using System;
namespace Senparc.Weixin.MP.AdvancedAPIs
{
	public static class CardApi
	{
		public static CardCreateResultJson CreateCard(string accessTokenOrAppId, BaseCardInfo cardInfo, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardCreateResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/create?access_token={0}", accessToken);
				CardCreateInfo data = null;
				CardType cardType = cardInfo.GetCardType();
				switch (cardType)
				{
				case CardType.GENERAL_COUPON:
					data = new CardCreateInfo
					{
						card = new Card_GeneralCoupon
						{
							card_type = cardType.ToString(),
							general_coupon = cardInfo as Card_GeneralCouponData
						}
					};
					break;
				case CardType.GROUPON:
					data = new CardCreateInfo
					{
						card = new Card_Groupon
						{
							card_type = cardType.ToString(),
							groupon = cardInfo as Card_GrouponData
						}
					};
					break;
				case CardType.DISCOUNT:
					data = new CardCreateInfo
					{
						card = new Card_DisCount
						{
							card_type = cardType.ToString(),
							discount = cardInfo as Card_DisCountData
						}
					};
					break;
				case CardType.GIFT:
					data = new CardCreateInfo
					{
						card = new Card_Gift
						{
							card_type = cardType.ToString(),
							gift = cardInfo as Card_GiftData
						}
					};
					break;
				case CardType.CASH:
					data = new CardCreateInfo
					{
						card = new Card_Cash
						{
							card_type = cardType.ToString(),
							cash = cardInfo as Card_CashData
						}
					};
					break;
				case CardType.MEMBER_CARD:
					data = new CardCreateInfo
					{
						card = new Card_MemberCard
						{
							card_type = cardType.ToString(),
							member_card = cardInfo as Card_MemberCardData
						}
					};
					break;
				case CardType.SCENIC_TICKET:
					data = new CardCreateInfo
					{
						card = new Card_ScenicTicket
						{
							card_type = cardType.ToString(),
							scenic_ticket = cardInfo as Card_ScenicTicketData
						}
					};
					break;
				case CardType.MOVIE_TICKET:
					data = new CardCreateInfo
					{
						card = new Card_MovieTicket
						{
							card_type = cardType.ToString(),
							movie_ticket = cardInfo as Card_MovieTicketData
						}
					};
					break;
				case CardType.BOARDING_PASS:
					data = new CardCreateInfo
					{
						card = new Card_BoardingPass
						{
							card_type = cardType.ToString(),
							boarding_pass = cardInfo as Card_BoardingPassData
						}
					};
					break;
				case CardType.LUCKY_MONEY:
					data = new CardCreateInfo
					{
						card = new Card_LuckyMoney
						{
							card_type = cardType.ToString(),
							lucky_money = cardInfo as Card_LuckyMoneyData
						}
					};
					break;
				case CardType.MEETING_TICKET:
					data = new CardCreateInfo
					{
						card = new Card_MeetingTicket
						{
							card_type = cardType.ToString(),
							meeting_ticket = cardInfo as Card_MeetingTicketData
						}
					};
					break;
				}
				return CommonJsonSend.Send<CardCreateResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CreateQRResultJson CreateQR(string accessTokenOrAppId, string cardId, string code = null, string openId = null, string expireSeconds = null, bool isUniqueCode = false, string balance = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CreateQRResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/qrcode/create?access_token={0}", accessToken);
				var data = new
				{
					action_name = "QR_CARD",
					action_info = new
					{
						card = new
						{
							card_id = cardId,
							code = code,
							openid = openId,
							expire_seconds = expireSeconds,
							is_unique_code = false,
							balance = balance
						}
					}
				};
				return CommonJsonSend.Send<CreateQRResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static ShelfCreateResultJson ShelfCreate(string accessTokenOrAppId, ShelfCreateData data, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<ShelfCreateResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/landingpage/create?access_token={0}", accessToken);
				return CommonJsonSend.Send<ShelfCreateResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult CodeDeposit(string accessTokenOrAppId, string cardId, string[] codeList, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("http://api.weixin.qq.com/card/code/deposit?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId,
					code = codeList
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static GetDepositCountResultJson GetDepositCount(string accessTokenOrAppId, string cardId, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<GetDepositCountResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("http://api.weixin.qq.com/card/code/getdepositcount?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId
				};
				return CommonJsonSend.Send<GetDepositCountResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CheckCodeResultJson CheckCode(string accessTokenOrAppId, string cardId, string[] codeList, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CheckCodeResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("http://api.weixin.qq.com/card/code/checkcode?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId,
					code = codeList
				};
				return CommonJsonSend.Send<CheckCodeResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static GetHtmlResult GetHtml(string accessTokenOrAppId, string cardId, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<GetHtmlResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/mpnews/gethtml?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId
				};
				return CommonJsonSend.Send<GetHtmlResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardConsumeResultJson CardConsume(string accessTokenOrAppId, string code, string cardId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardConsumeResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/code/consume?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId
				};
				return CommonJsonSend.Send<CardConsumeResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardDecryptResultJson CardDecrypt(string accessTokenOrAppId, string encryptCode, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardDecryptResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/code/decrypt?access_token={0}", accessToken);
				var data = new
				{
					encrypt_code = encryptCode
				};
				return CommonJsonSend.Send<CardDecryptResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardDeleteResultJson CardDelete(string accessTokenOrAppId, string cardId, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardDeleteResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/delete?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId
				};
				return CommonJsonSend.Send<CardDeleteResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardGetResultJson CardGet(string accessTokenOrAppId, string code, string cardId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardGetResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/code/get?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId
				};
				return CommonJsonSend.Send<CardGetResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardBatchGetResultJson CardBatchGet(string accessTokenOrAppId, int offset, int count, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardBatchGetResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/batchget?access_token={0}", accessToken);
				var data = new
				{
					offset,
					count
				};
				return CommonJsonSend.Send<CardBatchGetResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static CardDetailGetResultJson CardDetailGet(string accessTokenOrAppId, string cardId, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<CardDetailGetResultJson>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/get?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId
				};
				return CommonJsonSend.Send<CardDetailGetResultJson>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult CardChangeCode(string accessTokenOrAppId, string code, string cardId, string newCode, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/code/update?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					new_code = newCode
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult CardUnavailable(string accessTokenOrAppId, string code, string cardId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/code/unavailable?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult CardUpdate(string accessTokenOrAppId, CardType cardType, object data, string cardId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/update?access_token={0}", accessToken);
				BaseCardUpdateInfo data2 = null;
				switch (cardType)
				{
				case CardType.MEMBER_CARD:
					data2 = new CardUpdate_MemberCard
					{
						card_id = cardId,
						member_card = data as Card_MemberCardUpdateData
					};
					break;
				case CardType.SCENIC_TICKET:
					data2 = new CardUpdate_ScenicTicket
					{
						card_id = cardId,
						scenic_ticket = data as Card_ScenicTicketData
					};
					break;
				case CardType.MOVIE_TICKET:
					data2 = new CardUpdate_MovieTicket
					{
						card_id = cardId,
						movie_ticket = data as Card_MovieTicketData
					};
					break;
				case CardType.BOARDING_PASS:
					data2 = new CardUpdate_BoardingPass
					{
						card_id = cardId,
						boarding_pass = data as Card_BoardingPassData
					};
					break;
				}
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data2, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult AuthoritySet(string accessTokenOrAppId, string[] openIds, string[] userNames, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/testwhitelist/set?access_token={0}", accessToken);
				var data = new
				{
					openid = openIds,
					username = userNames
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult MemberCardActivate(string accessTokenOrAppId, string membershipNumber, string code, string cardId, string activateBeginTime = null, string activateEndTime = null, string initBonus = null, string initBalance = null, string initCustomFieldValue1 = null, string initCustomFieldValue2 = null, string initCustomFieldValue3 = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/membercard/activate?access_token={0}", accessToken);
				var data = new
				{
					init_bonus = initBonus,
					init_balance = initBalance,
					membership_number = membershipNumber,
					code = code,
					card_id = cardId,
					activate_begin_time = activateBeginTime,
					activate_end_time = activateEndTime,
					init_custom_field_value1 = initCustomFieldValue1,
					init_custom_field_value2 = initCustomFieldValue2,
					init_custom_field_value3 = initCustomFieldValue3
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult ActivateUserFormSet(string accessTokenOrAppId, ActivateUserFormSetData data, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/membercard/activateuserform/set?access_token={0}", accessToken);
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult RecommendSet(string accessTokenOrAppId, string cardId, CardCell cardCellData = null, UrlCell urlCellData = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/update?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId,
					member_card = new
					{
						base_info = new
						{
							modify_msg_operation = new
							{
								card_cell = cardCellData,
								url_cell = urlCellData
							}
						}
					}
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult PayCellSet(string accessTokenOrAppId, string cardId, bool isOpen, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/paycell/set?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId,
					is_open = isOpen
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static UpdateUserResult UpdateUser(string accessTokenOrAppId, string code, string cardId, int addBonus, int addBalance, int? bonus = null, int? balance = null, string recordBonus = null, string recordBalance = null, string customFieldValue1 = null, string customFieldValue2 = null, string customFieldValue3 = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<UpdateUserResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/membercard/updateuser?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					add_bonus = addBonus,
					bonus = bonus,
					record_bonus = recordBonus,
					add_balance = addBalance,
					balance = balance,
					record_balance = recordBalance,
					custom_field_value1 = customFieldValue1,
					custom_field_value2 = customFieldValue2,
					custom_field_value3 = customFieldValue3
				};
				return CommonJsonSend.Send<UpdateUserResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static MemberCardDeal MemberCardDeal(string accessTokenOrAppId, string code, string cardId, string recordBonus, decimal addBonus, decimal addBalance, string recordBalance, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<MemberCardDeal>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/membercard/updateuser?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					record_bonus = recordBonus,
					add_bonus = addBonus,
					add_balance = addBalance,
					record_balance = recordBalance
				};
				return CommonJsonSend.Send<MemberCardDeal>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult MovieCardUpdate(string accessTokenOrAppId, string code, string cardId, string ticketClass, string showTime, int duration, string screeningRoom, string[] seatNumbers, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/movieticket/updateuser?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					ticket_class = ticketClass,
					show_time = showTime,
					duration = duration,
					screening_room = screeningRoom,
					seat_number = seatNumbers
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult BoardingPassCheckIn(string accessTokenOrAppId, string code, string cardId, string passengerName, string classType, string seat, string etktBnr, string qrcodeData, bool isCancel = false, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/boardingpass/checkin?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					passenger_name = passengerName,
					@class = classType,
					seat = seat,
					etkt_bnr = etktBnr,
					qrcode_data = qrcodeData,
					is_cancel = isCancel
				};
				return CommonJsonSend.Send<WxJsonResult>(accessToken, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult UpdateUserBalance(string accessTokenOrAppId, string code, string cardId, decimal balance, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/luckymoney/updateuserbalance?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					balance = balance
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult UpdateMeetingTicket(string accessTokenOrAppId, string code, string cardId = null, string zone = null, string entrance = null, string seatNumber = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/meetingticket/updateuser?access_token={0}", accessToken);
				var data = new
				{
					code = code,
					card_id = cardId,
					zone = zone,
					entrance = entrance,
					seat_number = seatNumber
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static GetCardListResult GetCardList(string accessTokenOrAppId, string openId, string cardId = null, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<GetCardListResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/user/getcardlist?access_token={0}", accessToken);
				var data = new
				{
					openid = openId,
					card_id = cardId
				};
				return CommonJsonSend.Send<GetCardListResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
		public static WxJsonResult ModifyStock(string accessTokenOrAppId, string cardId, int increaseStockValue = 0, int reduceStockValue = 0, int timeOut = 10000)
		{
			return ApiHandlerWapper.TryCommonApi<WxJsonResult>(delegate(string accessToken)
			{
				string urlFormat = string.Format("https://api.weixin.qq.com/card/modifystock?access_token={0}", accessToken);
				var data = new
				{
					card_id = cardId,
					increase_stock_value = increaseStockValue,
					reduce_stock_value = reduceStockValue
				};
				return CommonJsonSend.Send<WxJsonResult>(null, urlFormat, data, CommonJsonSendType.POST, timeOut, false);
			}, accessTokenOrAppId, true);
		}
	}
}
